//
//  BCSettingsViewController.m
//  Memo
//
//  Created by bonc on 13-9-10.
//  Copyright (c) 2013年 fuzhengbang. All rights reserved.
//

#import "BCSettingsViewController.h"
#import "BCDateBase.h"

@interface BCSettingsViewController ()
@property (strong,nonatomic) UITableView* mytable;
@end

@implementation BCSettingsViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title=@"设置";
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
//    if (IOS_VERSION_Above_7_0) {
//        self.edgesForExtendedLayout=UIRectEdgeNone;
//    }
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(dismiss)];
    
    self.mytable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-44) style:UITableViewStyleGrouped];
    self.mytable.delegate=self;
    self.mytable.dataSource=self;
    self.mytable.bounces=NO;
    [self.view addSubview:self.mytable];
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dismiss
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark TableView Delegate Method and TableView DataSource Method

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier=@"SettingsCell";
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text=@"清理过期任务";
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIAlertView* alert=[[UIAlertView alloc]initWithTitle:@"注意" message:@"本操作将清理所有过期任务，请慎重操作" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alert show];
}

#pragma mark -
#pragma mark AlerView Delegate Method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==1) {
        NSDate* date=[NSDate date];
        NSDateComponents* comp=[[NSDateComponents alloc]init];
        [comp setHour:8];
        NSCalendar* cal=[[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
        date=[cal dateByAddingComponents:comp toDate:date options:0];
        
        [[BCDateBase defaultBase] deleteNotesBeforeTime:date];
    }
}

@end
